#!/usr/bin/env python
"""
docstring
"""

__author__ = 'rx.wen218@gmail.com'

import unittest
import datetime
from core import timezone 

class TimezoneTest(unittest.TestCase):
    def setUp(self):
        pass

    def testInvalidConstructor(self):
        self.assertRaises(ValueError, timezone.Timezone, '0:00')
        self.assertRaises(ValueError, timezone.Timezone, '00:0')
        self.assertRaises(ValueError, timezone.Timezone, '+00:0')
        self.assertRaises(ValueError, timezone.Timezone, '+8:00')
        self.assertRaises(ValueError, timezone.Timezone, '-00:0')
        self.assertRaises(ValueError, timezone.Timezone, 'aa:aa')
        self.assertRaises(ValueError, timezone.Timezone, '0000')

    def testInvalidRange(self):
        self.assertRaises(ValueError, timezone.Timezone, '13:00')
        self.assertRaises(ValueError, timezone.Timezone, '12:60')
        self.assertRaises(ValueError, timezone.Timezone, '12:61')
        self.assertRaises(ValueError, timezone.Timezone, '-13:00')
        self.assertRaises(ValueError, timezone.Timezone, '-12:60')
        self.assertRaises(ValueError, timezone.Timezone, '-12:61')
        self.assertRaises(ValueError, timezone.Timezone, '+13:00')
        self.assertRaises(ValueError, timezone.Timezone, '+12:60')
        self.assertRaises(ValueError, timezone.Timezone, '+12:61')

    def testUTCTimezone(self):
        delta = datetime.timedelta(0)
        tzinfo = timezone.Timezone()
        self.assertEqual(delta, tzinfo.utcoffset())
        self.assertEqual('GMT', tzinfo.tzname())
        tzinfo = timezone.Timezone('+00:00')
        self.assertEqual(delta, tzinfo.utcoffset())
        self.assertEqual('GMT', tzinfo.tzname())
        tzinfo = timezone.Timezone('00:00')
        self.assertEqual(delta, tzinfo.utcoffset())
        self.assertEqual('GMT', tzinfo.tzname())
        tzinfo = timezone.Timezone('-00:00')
        self.assertEqual(delta, tzinfo.utcoffset())
        self.assertEqual('GMT', tzinfo.tzname())

    def testEastTimezone(self):
        delta = datetime.timedelta(seconds=28800)
        tzinfo = timezone.Timezone('+08:00')
        self.assertEqual(delta, tzinfo.utcoffset())
        self.assertEqual('GMT+8', tzinfo.tzname())
        tzinfo = timezone.Timezone('08:00')
        self.assertEqual(delta, tzinfo.utcoffset())
        self.assertEqual('GMT+8', tzinfo.tzname())

        delta = datetime.timedelta(seconds=43200)
        tzinfo = timezone.Timezone('+12:00')
        self.assertEqual(delta, tzinfo.utcoffset())
        self.assertEqual('GMT+12', tzinfo.tzname())


    def testWestTimezone(self):
        delta = datetime.timedelta(seconds=-28800)
        tzinfo = timezone.Timezone('-08:00')
        self.assertEqual(delta, tzinfo.utcoffset())
        self.assertEqual('GMT-8', tzinfo.tzname())

        delta = datetime.timedelta(seconds=-43200)
        tzinfo = timezone.Timezone('-12:00')
        self.assertEqual(delta, tzinfo.utcoffset())
        self.assertEqual('GMT-12', tzinfo.tzname())
 
if __name__ == '__main__':
    unittest.main()
